package iit.projects.etaxi.view.bean;

import java.lang.reflect.Proxy;

import iit.projects.etaxi.model.service.CityService;
import iit.projects.etaxi.model.service.CustomerService;
import iit.projects.etaxi.model.service.DriverService;
import iit.projects.etaxi.model.service.MessageService;
import iit.projects.etaxi.model.service.OperatorService;
import iit.projects.etaxi.model.service.ReservationService;
import iit.projects.etaxi.model.service.ServiceInvocationHandler;
import iit.projects.etaxi.model.service.ServiceLocator;
import iit.projects.etaxi.model.service.SmsService;
import iit.projects.etaxi.model.service.SubCityService;
import iit.projects.etaxi.model.service.VehicleService;

public class ServiceLocatorBackingBean implements ServiceLocator {

	private CustomerService customerService;
	
	private DriverService driverService;
	
	private CityService cityService;
	
	private SubCityService subCityService;
	
	private ReservationService reservationService;
	
	private VehicleService vehicleService;
	
	private OperatorService operatorService;
	
	private SmsService smsService;
	
	private MessageService messageService;
	
	private Object getProxyService(Object service){
		return Proxy.newProxyInstance(service.getClass().getClassLoader(), 
									  service.getClass().getInterfaces(), 
									  new ServiceInvocationHandler(service));
	}

	@Override
	public CustomerService getCustomerService() {
		return customerService;
	}

	public void setCustomerService(CustomerService customerService) {
		this.customerService = (CustomerService)getProxyService(customerService);
	}
	
	@Override
	public DriverService getDriverService() {
		return driverService;
	}

	public void setDriverService(DriverService driverService) {
		this.driverService = (DriverService)getProxyService(driverService);
	}

	@Override
	public CityService getCityService() {
		return cityService;
	}

	public void setCityService(CityService cityService) {
		this.cityService = (CityService)getProxyService(cityService);
	}

	public SubCityService getSubCityService() {
		return subCityService;
	}

	public void setSubCityService(SubCityService subCityService) {
		this.subCityService = (SubCityService)getProxyService(subCityService);
	}

	public ReservationService getReservationService() {
		return reservationService;
	}

	public void setReservationService(ReservationService reservationService) {
		this.reservationService = (ReservationService)getProxyService(reservationService);
	}
	
	/**
	 * @param vehicleService the vehicleService to set
	 */
	public void setVehicleService(VehicleService vehicleService) {
		this.vehicleService = (VehicleService)getProxyService(vehicleService);
	}

	/**
	 * @return the vehicleService
	 */
	public VehicleService getVehicleService() {
		return vehicleService;
	}

	public OperatorService getOperatorService() {
		return operatorService;
	}

	public void setOperatorService(OperatorService operatorService) {
		this.operatorService = (OperatorService)getProxyService(operatorService);
	}

	public SmsService getSmsService() {
		return smsService;
	}

	public void setSmsService(SmsService smsService) {
		this.smsService = (SmsService)getProxyService(smsService);
	}

	public MessageService getMessageService() {
		return messageService;
	}

	public void setMessageService(MessageService messageService) {
		this.messageService = (MessageService)getProxyService(messageService);
	}
	
}
